<?php
	class Model_category extends CI_Model{
		protected $_table = "tbl_questions";
		protected $_category = "tbl_category";
		protected $_categori = "tbl_categorie";
		protected $_answers = "tbl_answers";
		public function __construct(){
			parent::__construct();
		}
		public function getdata($id){
			$this->db->where("rewrite",$id);
			return $this->db->get($this->_category)->row_array();
		}
		public function getcoments($quesid){
			$this->db->where("quesid",$quesid);
			return $this->db->count_all_results($this->_answers);
		}
		public function getcago($cateid){
			$this->db->where("cateid",$cateid);
			$this->db->limit(3);
			return $this->db->get($this->_categori)->result_array();
		}
		public function count_all($id){
			$this->db->join("tbl_user","tbl_user.user_id = tbl_questions.userid");
			$this->db->where("cateid",$id);
			return $this->db->count_all_results($this->_table);
		}
		public function list_all($id,$off,$start){
			$this->db->join("tbl_user","tbl_user.user_id = tbl_questions.userid");
			$this->db->where("cateid",$id);
			$this->db->order_by("id","desc");
			$this->db->limit($off,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function list_all_new($off,$start){
			$this->db->order_by("id","desc");
			$this->db->limit($off,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function count_all_new(){
			return $this->db->count_all_results($this->_table);
		}
	}